<?php
/**
 * 内容管理
 *
 * @package         YDCMS
 * @author          QQ:644157559 <644157559@qq.com>
 * @version         $Id: ContentModel.class.php v1.0 2014-06-13 17:27:03 $
 */
namespace Admin\Model;
class ContentModel extends CommonModel{
    // realtions
    protected $_link = array(
        // 一个模型拥有多个字段
        'Contype' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Contype',
            'foreign_key' => 'typeid',
            'as_fields' => 'typename',
        )//,
        /*'Model' => array(
            'mapping_type' => self::BELONGS_TO,
            'class_name' => 'Model',
            'foreign_key' => 'mid',
            'as_fields' => 'addtable',
        )*/
    );
    
    //自动验证
    protected $_validate = array(
        //array(验证字段1,验证规则,错误提示,[验证条件,附加规则,验证时间]),
        array('title', 'require', '文档标题必须填写', 1),
        array('typeid', 'CheckType', "您选择的栏目有误", 1, 'callback')
    );
    //自动完成
    protected $_auto = array(
        array('status', '1'),
        array('pubdate', 'time', 1, 'function'),
        array('writer', 'getUserName', 1, "function")
    );
    
    /**
     * 验证栏目是否存在
     * @param type $typeid
     * @return boolean
     */
    public function CheckType($typeid) {
        $types_info = D("Contype", "Service")->getById($typeid);
        if(isArrayAndNotEmpty($types_info)){
            return true;
        }else{
            return false;
        }
    }
}
